#!/bin/bash
HERE=$(cd "$(dirname "$0")";pwd)

VERSION=20190513
echo "TIM appimage was made in $VERSION"
echo "TIM appimage was made in $VERSION"
echo "在UBUNTU18.04需要安装32位支持库，通过以下命令即可安装 sudo apt install libgl1-mesa-glx:i386  libfreetype6:i386"
echo "为保证最佳的使用体验，正确使用托盘图标功能，Ubuntu18.04的GNOME桌面应安装topsicons插件。如果觉得字体奇怪，请给系统安装宋体字体，或者通过以下方式安装：将宋体文件simsun.ttf挎到 $HOME/.DeepinTIM.Appimage/drive_c/windows/Fonts目录下（该目录可自行创建）。"


if [ $EUID -eq 0 ]; then
    echo "Please not run TIM as root. Please run it without sudo"
    exit 1
fi

RO_DATADIR="$HERE/Deepin-TIM/"
export RW_DATADIR="$HOME/.DeepinTIM.unionfs"
mkdir -p $RW_DATADIR $HOME/.DeepinTIM.Appimage
$HERE/usr/bin/unionfs-fuse -o use_ino,nonempty,uid=$UID -o cow "$HOME/.DeepinTIM.Appimage"=RW:"$RO_DATADIR"=RO "$RW_DATADIR" || exit 1 #处理TIM运行产生的数据

if [ $(cat /proc/sys/kernel/unprivileged_userns_clone) == "1" ]; then
	unshare -mr  $HERE/runtim
else
	$HERE/runtim-proot
fi

function finish {
  echo "Cleaning up"
  killall $HERE/usr/bin/unionfs-fuse
}
trap finish EXIT
